package web.suzy.oj.controller.file;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.service.file.MarkDownFileService;

import javax.annotation.Resource;
import java.util.Map;

/**
 * YangSuzy 软件工作室
 * 类名: MarkDownFileController
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/12/8 11:21
 */
@Controller
@RequestMapping("/api/file")
public class MarkDownFileController {
    @Resource
    private MarkDownFileService markDownFileService;

    /**
     * 方法名: uploadMd
     * 描述: 上传markdown文件
     *
     * @param file
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/12/8 11:23
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/upload-md-file", method = RequestMethod.POST)
    @RequiresAuthentication
    @ResponseBody
    public ResultBean<Map<Object, Object>> uploadMd(@RequestParam("file") MultipartFile file) {
        return markDownFileService.uploadMd(file);
    }

    /**
     * 方法名: uploadMDImg
     * 描述: markdown上传照片
     *
     * @param image
     * @return web.suzy.oj.common.result.ResultBean<java.util.Map < java.lang.Object, java.lang.Object>>
     * @date 2022/12/8 15:07
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/upload-md-img", method = RequestMethod.POST)
    @RequiresAuthentication
    @ResponseBody
    public ResultBean<Map<Object, Object>> uploadMDImg(@RequestParam("image") MultipartFile image) {
        return markDownFileService.uploadMDImg(image);
    }

    /**
     * 方法名: deleteMDImg
     * 描述: markdown删除图片
     *
     * @param fileId
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/12/8 15:23
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/delete-md-img", method = RequestMethod.GET)
    @RequiresAuthentication
    @ResponseBody
    public ResultBean<Void> deleteMDImg(@RequestParam("fileId") Long fileId) {
        return markDownFileService.deleteMDImg(fileId);
    }
}
